functor SymTabFun(type T):
	sig 
	    type symbol
	    val resetSymTab : unit -> unit
	    val beginScope : unit -> unit
	    val endScope   : unit -> unit
	    val insert : string * symbol -> unit
	    val lookup : string -> symbol option 
	end
=
struct
type symbol = T
              
val init_size= 128

val hash= HashString.hashString
          
val cmp:string * string->bool = (op =)

exception not_found
		   
type tab = (string,symbol) HashTable.hash_table

fun newTable ():tab = HashTable.mkTable (hash,cmp) (init_size,not_found)

val symtab: tab list ref = ref [newTable()]

fun resetSymTab () = symtab:=[newTable()]

fun beginScope () =
    symtab := newTable()::(!symtab)

fun endScope () =
    symtab := tl (!symtab)

fun show () = 
    List.map HashTable.listItemsi (!symtab)
                     
fun insert (s:string*symbol) = HashTable.insert (hd (!symtab)) s

fun lookup name = 
    let val tab = List.find
		      (fn tab =>
			  case HashTable.find tab name of SOME _ => true | _ => false)
		      (!symtab)
    in 
	case tab of 
	    SOME table => HashTable.find table name
	  | _ => NONE 
    end
end



